package com.df.excel_export.web;

import com.df.excel_export.common.ExcelTableManager;
import com.df.excel_export.common.R;
import com.df.excel_export.project_config.ProjectConfig;
import com.df.excel_export.project_config.ProjectConfigManager;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController()
@RequestMapping("project")
public class ProjectController {


    @GetMapping("list")
    public R list() {
        List<ProjectConfig> projects = ProjectConfigManager.getIns().getCfgs();
        R r = R.ok().setData(projects);
        return r;
    }
    @PostMapping("saveCfg")
    public R saveCfg(@RequestBody @Validated ProjectConfig cfg) {

        //校验检查
        List<ProjectConfig> cfgs = ProjectConfigManager.getIns().getCfgs();
        cfgs.add(cfg);
        ProjectConfigManager.getIns().save2Disk();
        R r = R.ok();
        return r;
    }
}
